package com.hejia.alauda.entity;

import java.util.Date;

import javax.persistence.Column;

/**
 * 还款订单实体
 * 资产到期和红包提现还款使用
 * 
 * Created by showone on 2014 下午5:57:53.
 */
public class RepaymentOrder extends BaseEntity {

	public static final String FINANCING_ID_SEPARATOR = ",";//金融包ID分隔符
	public static final String TRANSACTION_ONLINE="online";
	public static final String TRANSACTION_OFFLINE="offline";

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/*
	 * STATUS_APPLY申请提交
	 * STATUS_SUBMIT已提交支付网管
	 * STATUS_SUCCESS支付成功
	 * STATUS_PROCESSING银行处理中
	 * STATUS_FAILURE支付失败
	 */
	public enum Status {
		STATUS_NEW,STATUS_SUBMIT_FAILURE,STATUS_APPLY, STATUS_SUBMIT, STATUS_SUCCESS, STATUS_PROCESSING, STATUS_FAILURE;
	}
	
	/**
	 * 还款任务执行状态，后台执行提交到第三方支付过程使用
	 * @author hyr
	 *
	 */
	public enum RepayExecuteStatus {
		
		/**
		 * 等待执行
		 */
		AWAITING,
		
		/**
		 * 正在执行
		 */
		EXECUTING,
		
		/**
		 * 执行结束
		 */
		END,
		
		/**
		 * 执行发生错误
		 */
		ERROR
	}

	@Column
	private String orderNumber;// 订单号，红包提现还款时订单号为【订单号】+【B】+【首笔红包订单ID】

	@Column
	private String financingIds;// 金融包Id集，为空时表示红包提现还款，不为空表示资产到期还款

	@Column
	private Double amount; // 还款金额

	@Column
	private BankCard bankcard; // 还款银行

	@Column
	private String cardNumber;// 银行卡卡号

	@Column
	private String bankName;// 银行名称

	@Column
	private String userName;// 收款人姓名

	@Column
	private String description;// 描述
	
	@Column
	private Long userId;// 用户id

	@Column
	private Status status;
	
	private String statusValue;
	
	@Column
	private Date repayTime;// 还款时间

	@Column
	private String transaction;// 交易类型：online,offline
	
	@Column
	private String payGateCode;// 支付网关编码
	
	@Column
	private RepayExecuteStatus repayExecuteStatus; // 还款执行状态

	public String getOrderNumber() {
		return orderNumber;
	}

	public void setOrderNumber(String orderNumber) {
		this.orderNumber = orderNumber;
	}

	public String getFinancingIds() {
		return financingIds;
	}

	public void setFinancingIds(String financingIds) {
		this.financingIds = financingIds;
	}

	public Double getAmount() {
		return amount;
	}

	public void setAmount(Double amount) {
		this.amount = amount;
	}

	public BankCard getBankcard() {
		return bankcard;
	}

	public void setBankcard(BankCard bankcard) {
		this.bankcard = bankcard;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getCardNumber() {
		return cardNumber;
	}

	public void setCardNumber(String cardNumber) {
		this.cardNumber = cardNumber;
	}

	public String getBankName() {
		return bankName;
	}

	public void setBankName(String bankName) {
		this.bankName = bankName;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public String getStatusValue() {
		statusValue = "未知状态";
		if (getStatus() != null) {
			switch (getStatus()) {
			case STATUS_APPLY:
				statusValue = "申请还款";
				break;
			case STATUS_SUBMIT:
				statusValue = "已提交网关";
				break;
			case STATUS_SUCCESS:
				statusValue = "交易成功";
				break;
			case STATUS_PROCESSING:
				statusValue = "银行处理中";
				break;
			case STATUS_FAILURE:
				statusValue = "交易失败";
				break;
			default:
				break;
			}
		}
		return statusValue;
	}

	public String getTransaction() {
		return transaction;
	}

	public void setTransaction(String transaction) {
		this.transaction = transaction;
	}

	public Date getRepayTime() {
		return repayTime;
	}

	public void setRepayTime(Date repayTime) {
		this.repayTime = repayTime;
	}
	
	public String getPayGateCode() {
		return payGateCode;
	}

	public void setPayGateCode(String payGateCode) {
		this.payGateCode = payGateCode;
	}
	
	public RepayExecuteStatus getRepayExecuteStatus() {
		return repayExecuteStatus;
	}

	public void setRepayExecuteStatus(RepayExecuteStatus repayExecuteStatus) {
		this.repayExecuteStatus = repayExecuteStatus;
	}
	
	//银行卡尾号
	public String getLastDigitsOfCardNumber(){
		return (cardNumber!=null && cardNumber.length()>4)?cardNumber.substring(cardNumber.length()-4, cardNumber.length()):"";
	} 

}
